<html>
<head><meta charset="utf-8"><title>Copying uninitialized memory · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying.20uninitialized.20memory.html">Copying uninitialized memory</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190735359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying%20uninitialized%20memory/near/190735359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying.20uninitialized.20memory.html#190735359">(Mar 16 2020 at 15:10)</a>:</h4>
<p>Is it legal to copy uninitialized memory using <code>ptr::copy_nonoverlapping</code>? The use case here is for hashbrown's <code>Clone</code> implementation, where (for <code>Copy</code> types) we copy the entire bucket array, some of which may be empty (and therefore uninitialized).</p>



<a name="190745563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying%20uninitialized%20memory/near/190745563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying.20uninitialized.20memory.html#190745563">(Mar 16 2020 at 16:20)</a>:</h4>
<p>Yes, the memory is just still uninitialized at the destination as well.</p>



<a name="190838552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying%20uninitialized%20memory/near/190838552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Copying.20uninitialized.20memory.html#190838552">(Mar 17 2020 at 12:15)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> also see <a href="https://github.com/rust-lang/rust/pull/67827" target="_blank" title="https://github.com/rust-lang/rust/pull/67827">https://github.com/rust-lang/rust/pull/67827</a>. there was an attempt to put this into the docs but it died off.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>